package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.service.TestService;
import com.atguigu.tingshu.common.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.DelayQueue;
import java.util.concurrent.TimeUnit;

/**
 * @author atguigu-mqx
 * @ClassName TestController
 * @description: TODO
 * @date 2023年12月05日
 * @version: 1.0
 */
@RestController
@RequestMapping("api/album/test")
public class TestController {

    @Autowired
    private TestService testService;

    /**
     * 测试分布式锁
     * @return
     */
    @GetMapping("testLock")
    public Result testLock(){
        //  调用服务层方法
        testService.testLock();
        return Result.ok();
    }

    public static void main(String[] args) throws InterruptedException {
        ArrayBlockingQueue<String> queue = new ArrayBlockingQueue<>(3);

        System.out.println(queue.offer("a"));
        System.out.println(queue.offer("b"));
        System.out.println(queue.offer("c"));

        //  queue.put("d");
        //  具有阻塞特点.
        //          System.out.println(queue.take());
        //
        //        System.out.println(queue.offer("c"));
        //        System.out.println(queue.offer("d",3, TimeUnit.SECONDS));

    }
}
